package org.gruposp2p.aula.gwt.client.content.coursegroup;

import org.gruposp2p.aula.gwt.client.AulaApplication;
import org.gruposp2p.aula.gwt.client.AulaConstants;
import org.gruposp2p.aula.gwt.client.event.AulaEventBus;
import org.gruposp2p.aula.gwt.client.event.CoursegroupChangeEvent;
import org.gruposp2p.aula.gwt.client.event.CoursegroupChangeHandler;
import org.gruposp2p.aula.gwt.client.model.Coursegroup;
import org.gruposp2p.aula.gwt.client.representation.StudentsRepresentation;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class CoursegroupDataPanel extends VerticalPanel 
implements CoursegroupChangeHandler {
	
	private AulaApplication aulaApplication;
	private AulaConstants constants;
	private TextBox nameTextBox;
	private TextBox descriptionTextBox;
	
	public static interface CwConstants extends Constants {	}	
	
	public CoursegroupDataPanel (AulaApplication aulaApplication) {
		this.aulaApplication = aulaApplication;
		this.constants = aulaApplication.getConstants();

		add(new Label(constants.NewStudentDialogBoxNameLabel()));
	    nameTextBox = new TextBox ();
	    add(nameTextBox);

	    add(new Label(constants.NewStudentDialogBoxDescriptionLabel()));
	    descriptionTextBox = new TextBox();
	    add(descriptionTextBox);

	    Button acceptButton = new Button(constants.AcceptButtonCaption(),
		        new ClickHandler() {
		          public void onClick(ClickEvent event) {		        	  

		          }
		        });

	    HorizontalPanel hPanel = new HorizontalPanel();
	    hPanel.setSpacing(5);
	    hPanel.add(acceptButton);
	    
	    add(hPanel);

	    //To solve Firefox strange effect
	    nameTextBox.setFocus(true);		
	    setStylePrimaryName("tabbedForm");
		AulaEventBus.getInstance().registerToCoursegroupChange(this);
	}	

	private void setCoursegroup (Coursegroup coursegroup) {
		nameTextBox.setText(coursegroup.getLink().getName());
		descriptionTextBox.setText(coursegroup.getDescription());
	}
	
	@Override
	public void processCoursegroup(CoursegroupChangeEvent event) {
		setCoursegroup(event.getCoursegroup());		
	}

}